﻿<Window x:Class="MSIExtracter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MSIExtracter"
        xmlns:viewmodel="clr-namespace:MSIExtracter.ViewModel"
        xmlns:converter="clr-namespace:MSIExtracter.Converter"
        xmlns:dataRec="clr-namespace:MSIExtracter.Data"
        Title="msi previewer" Height="600" Width="700" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <Style TargetType="{x:Type DataGrid}">
            <Setter Property="Background" Value="White"></Setter>
            <Setter Property="GridLinesVisibility" Value="Vertical"></Setter>
            <Setter Property="RowHeaderWidth" Value="0"></Setter>
            <Setter Property="VerticalGridLinesBrush"
                 Value="{Binding ElementName=splitter, Path=Background}"></Setter>
        </Style>
        <viewmodel:MainWindowViewModel x:Key="ViewModel"></viewmodel:MainWindowViewModel>
        <converter:ValueConverter x:Key="ValueConverter"></converter:ValueConverter>
    </Window.Resources>
    <Grid DataContext="{StaticResource ViewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="120"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="24"></RowDefinition>
        </Grid.RowDefinitions>

        <Border Grid.Row="2" BorderThickness="0,1,0,0" BorderBrush="LightGray" Background="FloralWhite"/>
        
        <!--Row 0 - Gets the information from user to extract the MSI-->
        <Grid Grid.Row="0" Background="WhiteSmoke">
            <Grid.RowDefinitions>
                <RowDefinition Height="40"></RowDefinition>
                <RowDefinition Height="25"></RowDefinition>
                <RowDefinition Height="25"></RowDefinition>
                <RowDefinition Height="30"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20*"></ColumnDefinition>
                <ColumnDefinition Width="80*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <!--<Border Grid.Row="2" Background="WhiteSmoke"/>-->
            <Label x:Name="title" Content="msi previewer" 
                   Grid.Row="0" Grid.ColumnSpan="2" 
                   Foreground="Crimson" FontFamily="Comic Sans MS" FontWeight="Bold"
                   HorizontalAlignment="Left" FontSize="20"></Label>
            <Label x:Name="lblPath" Content="Path of MSI:" 
                   Grid.Row="1" Grid.Column="0" 
                   HorizontalAlignment="Right" VerticalAlignment="Center"></Label>
            <TextBox x:Name="txtPath" 
                     Grid.Row="1" Grid.Column="1" 
                     HorizontalAlignment="Left" Width="500" Height="20" VerticalAlignment="Center"></TextBox>
            <Label x:Name="lblTargetPath" Content="Target Path to Extract:" 
                   Grid.Row="2" Grid.Column="0" 
                   HorizontalAlignment="Right" VerticalAlignment="Center"></Label>
            <TextBox x:Name="txtTargetPath" 
                     Grid.Row="2" Grid.Column="1" 
                     HorizontalAlignment="Left" Width="500" Height="20" VerticalAlignment="Center"></TextBox>
            <Button x:Name="btnExtact" 
                    Grid.Row="3" Grid.ColumnSpan="2" 
                    HorizontalAlignment="Center" VerticalAlignment="Center"
                    Content="Extract"
                    Width="120" Height="24"
                    Command="{Binding Path=ExtractCommand}">
                <Button.CommandParameter>
                    <MultiBinding Converter="{StaticResource ValueConverter}">
                        <Binding Path="Text" ElementName="txtPath"/>
                        <Binding Path="Text" ElementName="txtTargetPath"/>
                    </MultiBinding>
                </Button.CommandParameter>
            </Button>
            
        </Grid>
        <!--Row 1 - Contains the tree view of extracted folder structure-->
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="180" MaxWidth="300"/>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TreeView Grid.Column="0" Name="directoryView" ItemsSource="{Binding Path=TargetLoc, Mode=TwoWay}">
                <TreeView.Resources>
                    <HierarchicalDataTemplate DataType="{x:Type dataRec:DirectoryRecord}"
                                      ItemsSource="{Binding Directories}" >
                        <TextBlock Text="{Binding Info.Name}" />
                    </HierarchicalDataTemplate>
                </TreeView.Resources>
            </TreeView>
            <GridSplitter Grid.Column="1"
                    Name="splitter"
                    Width="4"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Stretch"></GridSplitter>
            <DataGrid Grid.Column="2"
                   Name="fileView" ItemsSource="{Binding ElementName=directoryView, 
                                 Path=SelectedItem.Files}">
                   </DataGrid>
        </Grid>
        <!--Row2- Status bar- displays the messages on exceptions-->
        <TextBlock Grid.Row="2" Text="{Binding Path=StatusMsg}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,0,0,0"/>
    </Grid>
</Window>
